package com.wang.test;

import com.wang.users.pojo.Arole;
import com.wang.users.pojo.AroleEnum;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/**
 * 测试thymeleafController
 * @author Zjx
 */
@Log4j2
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {
    /**
     * 第一个示例
     * @return
     */
    @RequestMapping("/test01")
    public String test01(Model model){
        log.info("==执行了==");
        Map<String,Object> paramsMap = new HashMap<>(1);
        paramsMap.put("id", 10);
        paramsMap.put("name", "张三");
        paramsMap.put("htmlStr", "<h1>岳飞</h1>");
        paramsMap.put("age", 20);
        paramsMap.put("stTime",  new Date());
        String[] hobbyArr = {"足球Arr", "蓝球Arr", "乒乓球Arr"};
        paramsMap.put("hobbyArr",  hobbyArr);
        List hobbyList = Arrays.asList("足球List", "蓝球List", "乒乓球List");
        paramsMap.put("hobbyList",  hobbyList);

        Set hobbySet = new HashSet(1);
        hobbySet.add("足球Set");
        hobbySet.add("蓝球Set");
        hobbySet.add("乒乓球Set");
        paramsMap.put("hobbySet",  hobbySet);

        Map<String,Object> hobbyMap = new HashMap<>(1);
        hobbyMap.put("name1", "足球Map");
        hobbyMap.put("name2", "蓝球Map");
        hobbyMap.put("name3", "乒乓球Map");
        paramsMap.put("hobbyMap", hobbyMap);

        Arole role = new Arole();
        role.setName("测试1");
        role.setStatus(AroleEnum.STATUS_DISABLE.getCode());
        model.addAttribute("role",role);

        model.addAllAttributes(paramsMap);
        return "/thymeleaf/test01.html";
    }

    /**
     * 第一个示例
     * @return
     */
    @RequestMapping("/test02")
    public String test02(Model model){
        log.info("==执行了==");
        return "/thymeleaf/test02.html";
    }
}
